package com.nursebetty.droid.client.activity;

import com.nursebetty.droid.client.model.User;
import com.nursebetty.droid.client.model.UserHistory;
import com.nursebetty.droid.client.model.WeightModel;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;
import android.widget.TextView;

public class WeightHistory extends Activity {
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.weighthistory);
        
        final User user = (User) getIntent().getExtras().get("user");
        final UserHistory userHistory = (UserHistory) getIntent().getSerializableExtra("userHistory");
        
        TableLayout tl = (TableLayout) findViewById(R.id.tableLayout);
        TableRow th = new TableRow(this);
        TextView header1 = new TextView(this);
        header1.setText("Value");
        header1.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));
        header1.setTextColor(Color.BLACK);
        th.addView(header1);
        TextView header2 = new TextView(this);
        header2.setText("Date");
        header2.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));
        header2.setTextColor(Color.BLACK);
        th.addView(header2);
        tl.addView(th);
        
        for (WeightModel bm : userHistory.getWeightHistory()){
	        TableRow tr = new TableRow(this);
	        tr.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));   
	        TextView weight = new TextView(this);
	        weight.setText(String.valueOf(bm.getWeightValue()));
	        weight.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));
	        weight.setTextColor(Color.BLACK);
	        tr.addView(weight);
	        
	        TextView date = new TextView(this);
	        date.setText(bm.getTestDate().toString());
	        date.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));
	        date.setTextColor(Color.BLACK);
	        tr.addView(date);
	        tl.addView(tr,  new TableLayout.LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));
        }
	}

}
